//% color="#007FFF" iconWidth=40 iconHeight=40
namespace mqtt_plus {
  //% block="MQTT set ClientId [CLIENTID]"  blockType="command"
  //% CLIENTID.shadow="string"   CLIENTID.defl="Undefined"
  export function setClientId(parameter: any, block: any) {
    let cid = parameter.CLIENTID.code;
    Generator.addInclude("includeMqttPlus", "#include <mqtt_plus.h>");
    // Generator.addObject("IotObject", "DFRobot_Iot",`myIot;`);
    Generator.addCode(`setClientId(&myIot, ${cid});`);
  }

  //% block="MQTT Send retained message [DATA] to the topic [TOPIC] with QoS [QOS]" blockType="command"
  //% DATA.shadow="string"   DATA.defl="Hello"
  //% TOPIC.shadow="string"   TOPIC.defl="topic/a"
  //% QOS.shadow="dropdown"  QOS.options="QOS"
  export function sendRetainedMsg(parameter: any, block: any) {
    let msg = parameter.DATA.code;
    let topic = parameter.TOPIC.code;
    let qos = parameter.QOS.code;
    Generator.addInclude("includeMqttPlus", "#include <mqtt_plus.h>");
    Generator.addCode(`sendRetainedMessage(&myIot, ${topic}, ${msg}, ${qos});`);
  }

}
